using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;

namespace PCR.PCRControls
{
	public partial class PreHeatSection : UserControl, ISection, INotifyPropertyChanged, IComponentConnector
	{
		public static readonly DependencyProperty IsUseProperty = DependencyProperty.Register("IsUse", typeof(bool), typeof(PreHeatSection), new PropertyMetadata(true));

		public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(PreHeatSection), new FrameworkPropertyMetadata(false, OnIsSelectedChanged));

		private bool Click;

		public static readonly DependencyProperty TemperatureProperty = DependencyProperty.Register("Temperature", typeof(double), typeof(PreHeatSection), new FrameworkPropertyMetadata(20.0, OnTemperaturePropertyChanged));

		private bool StartTemptEditClick;

		public bool ScreenTest { get; set; }

		public bool IsUse
		{
			get
			{
				return (bool)GetValue(IsUseProperty);
			}
			set
			{
				SetValue(IsUseProperty, value);
			}
		}

		public bool IsSelected
		{
			get
			{
				return (bool)GetValue(IsSelectedProperty);
			}
			set
			{
				SetValue(IsSelectedProperty, value);
			}
		}

		public double Temperature
		{
			get
			{
				return (double)GetValue(TemperatureProperty);
			}
			set
			{
				if (value < 4.0)
				{
					value = 4.0;
				}
				if (value > 99.0)
				{
					value = 99.0;
				}
				SetValue(TemperatureProperty, value);
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		public PreHeatSection()
		{
			InitializeComponent();
		}

		public void OnPropertyChanged(string propName)
		{
			if (string.IsNullOrEmpty(propName))
			{
				throw new ArgumentException("propName");
			}
			if (this.PropertyChanged != null)
			{
				this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
			}
		}

		private static void OnIsSelectedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			PreHeatSection preHeatSection = obj as PreHeatSection;
			if (preHeatSection.IsSelected)
			{
				preHeatSection.Background = new SolidColorBrush(Colors.LightPink);
			}
			else
			{
				preHeatSection.Background = new SolidColorBrush(Colors.Transparent);
			}
		}

		private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			Click = true;
		}

		private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (Click)
			{
				Click = false;
				IsSelected = !IsSelected;
			}
		}

		private static void OnTemperaturePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			PreHeatSection preHeatSection = obj as PreHeatSection;
			preHeatSection.Temperature = preHeatSection.Temperature;
			preHeatSection.cStartMarginTop.Height = new GridLength(99.0 - preHeatSection.Temperature, GridUnitType.Star);
			preHeatSection.cStartMarginBot.Height = new GridLength(preHeatSection.Temperature - 4.0, GridUnitType.Star);
		}

		private void StartGridSplitter_DragDelta(object sender, DragDeltaEventArgs e)
		{
			double num = cStartMarginBot.ActualHeight + cStartMarginTop.ActualHeight;
			if (num <= 0.0)
			{
				num = 1.0;
			}
			Temperature = Convert.ToInt16(cStartMarginBot.ActualHeight / num * 95.0) + 4;
			BindingExpression bindingExpression = cStartTempt.GetBindingExpression(NumSpan.ValueProperty);
			if (bindingExpression != null)
			{
				bindingExpression.UpdateSource();
			}
		}

		private void StartTemptEdit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			StartTemptEditClick = true;
			e.Handled = true;
		}

		private void StartTemptEdit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (StartTemptEditClick)
			{
				StartTemptEditClick = false;
				cStartTempt.Visibility = Visibility.Visible;
				cStartTempt.Focus();
				cStartTempt1.Visibility = Visibility.Collapsed;
			}
		}

		private void cStartTempt_LostFocus(object sender, RoutedEventArgs e)
		{
			cStartTempt1.Visibility = Visibility.Visible;
			cStartTempt.Visibility = Visibility.Collapsed;
		}

		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		[DebuggerNonUserCode]
		internal Delegate _CreateDelegate(Type delegateType, string handler)
		{
			return Delegate.CreateDelegate(delegateType, this, handler);
		}
	}
}
